﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightCAD.MathLib.CSG
{
   class CorkTriMesh
    {
        public int n_triangles;
        public int n_vertices;
        public int[] triangles;
        public double[] vertices;
    }
   public class RawMesh
    {
        public List<CorkVertex> vertices = new List<CorkVertex>();
        public List<CorkTriangle> triangles = new List<CorkTriangle>();
    }

  public class CorkVertex
    {
        public bool manifold;
        public Vec3 pos = new Vec3(); // required for both RawMesh and Mesh
        public CorkVertex()
        {
        }
        public CorkVertex(double x, double y, double z)
        {
            pos.Set(x, y, z);
        }
        public void merge(CorkVertex v0, CorkVertex v1)
        {
            double a0 = 0.5;
            if (v0.manifold && !v1.manifold)
            {
                a0 = 0.0;
            }
            if (!v0.manifold && v1.manifold)
            {
                a0 = 1.0;
            }
            double a1 = 1.0 - a0;

            pos = a0 * v0.pos + a1 * v1.pos;
        }
        public void interpolate(CorkVertex v0, CorkVertex v1)
        {
            double a0 = 0.5;
            double a1 = 0.5;
            pos = a0 * v0.pos + a1 * v1.pos;
        }
        internal void isct(Mesh.IsctVertEdgeTriInput input)
        {
            Vec2 a_e = new Vec2(1, 1) / 2.0;
            Vec3 a_t = new Vec3(1, 1, 1) / 3.0;
            a_e /= 2.0;
            a_t /= 2.0;
        }
        internal void isct(Mesh.IsctVertTriTriTriInput input)
        {
            Vec3[] a = new Vec3[3];
            for (uint k = 0; k < 3; k++)
            {
                a[k] = new Vec3(1, 1, 1) / 3.0;
                a[k] /= 3.0;
            }
            for (uint i = 0; i < 3; i++)
            {
                for (uint j = 0; j < 3; j++)
                {
                }
            }
        }

       public void isctInterpolate(CorkVertex v0, CorkVertex v1)
        {
            double a0 = (v1.pos - pos).Length();
            double a1 = (v0.pos - pos).Length();
            if (a0 + a1 == 0.0) a0 = a1 = 0.5; // safety
            double sum = a0 + a1;
            a0 /= sum;
            a1 /= sum;
        }
    }

   public class CorkTriangle
    {
        internal byte bool_alg_data; // internal use by algorithm

        public int a;
        public int b;
        public int c;
        public CorkTriangle() { }
        public CorkTriangle(int a, int b, int c)
        {
            this.a = a;
            this.b = b;
            this.c = c;
        }

        public void merge(CorkTriangle UnnamedParameter, CorkTriangle UnnamedParameter2)
        {
        }
        public static void split(CorkTriangle UnnamedParameter, CorkTriangle UnnamedParameter2, CorkTriangle UnnamedParameter3)
        {
        }
        public void move(CorkTriangle UnnamedParameter)
        {
        }
        internal void subdivide(SubdivideTriInput input)
        {
            bool_alg_data = input.pt.bool_alg_data;
        }
    }

   class SubdivideTriInput
    {
        public CorkTriangle pt;
        public CorkVertex[] pv = new CorkVertex[3];
        public CorkVertex[] v = new CorkVertex[3];
    }
}
